﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using EnumHelper = ZBJF.Warranty.Common.Common.EnumHelper
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
@{
    ViewBag.Title = "处理待维修工单-查看基本信息";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}

<ul id="myTab" class="nav nav-tabs">
    <li class="active">
        <a href="#workOrderInfo" data-toggle="tab">
            工单信息
        </a>
    </li>
    <li>
        <a href="#remoteSortingAudit" data-toggle="tab">
            远程分拣审核
        </a>
    </li>
    <li>
        <a href="#processLog" data-toggle="tab">
            流程日志
        </a>
    </li>
    @*<li>
            <a href="#operateLog" data-toggle="tab">
                操作日志
            </a>
        </li>*@
</ul>
<div id="myTabContent" class="tab-content">
    <div class="tab-pane  fade in active" id="workOrderInfo">
        @using (Html.BeginForm("SaveInsuranceWarrantyRecord", "ToBeMaintainWorkOrder", FormMethod.Post, new { id = "mvcForm", name = "mvcForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
        {
            @Html.HiddenFor(m => m.ID)
            @Html.HiddenFor(m => m.InsuranceOrderId)
            <!--工单信息-->
            @RenderPage("/Views/WorkOrderCommonInfo/WorkOrderInfo.cshtml", new { insuranceWarrantyRecordID = Model.ID })
            <!--保单信息-->
            @RenderPage("/Views/WorkOrderCommonInfo/InsuranceOrderInfo.cshtml", new { insuranceWarrantyRecordID = Model.ID })
            <!--保单历史服务信息-->
            @RenderPage("/Views/WorkOrderCommonInfo/InsuranceOrderServiceHistory.cshtml", new { insuranceWarrantyRecordID = Model.ID })
            <!--销售商信息-->
            @RenderPage("/Views/WorkOrderCommonInfo/InsuranceOrderSellerInfo.cshtml", new { insuranceWarrantyRecordID = Model.ID })
            <h4>报案信息</h4>
            <table class="table table-responsive table-bordered table-hover">
                <tr>
                    <th class="w200">报案人：</th>
                    <td>@Html.TextBoxFor(m => m.Reporter, new { validate = "{CanNotContainsSpecialChar:true,required:true,messages:{required:'报案人必填！'}}", @class = "w-p98" })</td>
                    <th class="w200">报案人手机：</th>
                    <td>@Html.TextBoxFor(m => m.ReporterPhone, new { validate = "{isTelphone:true,required:true,messages:{required:'报案人手机必填！'}}", @class = "w-p98" })</td>
                </tr>
                <tr>
                    <th>对接理赔员</th>
                    <td>
                        @Html.TextBoxFor(m => m.InsuranceCompanyLossAdjusterName, new { validate = "{CanNotContainsSpecialChar:true,required:true,messages:{required:'对接理赔员必填！'}}", @class = "w-p98" })
                    </td>
                    <th></th>
                    <td></td>
                </tr>
            </table>
            if (ServiceFactory.InsuranceWarrantyRecordStatusServiceInstance.GetParentStatusCode(Model.Status) == (byte)InsuranceWarrantyStatus.Processing)
            {
                <h4>工单状态</h4>
                <select id="ParentStatus" name="ParentStatus" validate="{required:true,messages:{required:'请选择处理结果'}}">
                    <option value="@((byte) InsuranceWarrantyStatus.Processing)">@(EnumHelper.Instance.GetDescription(typeof(InsuranceWarrantyStatus), InsuranceWarrantyStatus.Processing))</option>
                </select>
                <select id="Status" name="Status" style="display: none;" validate="{required:true,messages:{required:'请选择处理结果'}}"></select>
                <span id="StatusReasonDiv" style="display: none;">
                    状态备注：
                    <select id="StatusReasonId" name="StatusReasonId" validate="{required:true,messages:{required:'请选择状态备注'}}"></select>
                </span>
            }
        }
        <!--合同凭证-->
        @RenderPage("/Views/WorkOrderCommonInfo/InsuranceWarrantyRecordContractInfo.cshtml", new { insuranceWarrantyRecordID = Model.ID })      
        <div class="form-actions text-center">
            @if (ServiceFactory.InsuranceWarrantyRecordStatusServiceInstance.GetParentStatusCode(Model.Status) == (byte)InsuranceWarrantyStatus.Processing)
            {
                <input class="btn btn-primary Edit-R" type="button" onclick="if($('#mvcForm').valid()){layer.load();$('#mvcForm').submit();}" value="提交">
            }
            <input class="btn" type="button" value="返回" onclick="location.href = '/ToBeMaintainWorkOrder'">
        </div>
    </div>
    <div class="tab-pane padding-10 fade in" id="remoteSortingAudit">
        <!--远程分拣信息-->
        @RenderPage("RemoteSortingAudit.cshtml", new { id = Model.ID })
    </div>
    <div class="tab-pane padding-10 fade in" id="processLog">
        @RenderPage("/Views/InsuranceWarrantyRecord/ProcessLogsIndex.cshtml", new { InsuranceWarrantyRecordId = Model.ID })
    </div>
    @*<div class="tab-pane padding-10 fade in" id="operateLog">
            @RenderPage("/Views/OpreateLogs/Index.cshtml", new { LogTableName = "InsuranceWarrantyRecord", LogTablePKID = Model.ID })
        </div>*@
</div>
@*---------------取消报案--------------*@
<div id="showCancelReport">
    <table style="margin: 0 auto; line-height: 50px;">
        <tr>
            <th>请选择取消原因：</th>
            <td>@Html.DropDownList("StatusReasonCancel", ConvertToSelector.Instance.StatusReasonConvertToSelectList(true, ((byte)InsuranceWarrantyStatus.Canceled)))</td>
        </tr>
    </table>
</div>
<div id="transferOrderModal" style="display: none">
    <table style="margin:0 auto;line-height:50px;">
        <tr>
            <th>转交给客服：</th>
            <td>@Html.DropDownList("TakeOverOrderServiceUserID", ConvertToSelector.Instance.SystemUserToSelectList(true, excludeUserID: Model.SystemServiceUserId ?? 0))</td>
        </tr>
    </table>
</div>
@section scripts
{
    @Scripts.Render("~/bundles/chosen")
    @Styles.Render("~/Content/chosen")
    <script type="text/javascript">
        $(function () {
            $("#showCancelReport").hide();//隐藏取消报单页面
            statusChange($("#ParentStatus"));
            //工单状态选择
            $("#ParentStatus").change(function () {
                statusChange($(this));
            });
            $("#Status").change(function () {
                GetStatusReason($(this).find("option:selected").data("id"));
            });
        });

        //任务状态选择
        function statusChange(parentStatus) {
            if (!parentStatus.val() || parentStatus.val() < 0) {
                $("#Status").val("").hide().html("");
                return;
            }
            $.ajax({
                url: "/Common/GetChildrenStatusByParentCode?parentStatus=" + parentStatus.val(),
                success: function (data) {
                    if (data && data.length > 0) {
                        var html = '<option value="">请选择</option>';
                        for (var i = 0; i < data.length; i++) {
                            html += "<option value='" + data[i].StatusCode + "' data-id='" + data[i].ID + "'>" + data[i].StatusName + "</option>";
                        }
                        $("#Status").show().html(html);
                    } else {
                        $("#Status").hide().html("");
                        $("#Status").val(parentStatus.val());
                    }
                    $("#Status").val("@(Model.Status)");
                    GetStatusReason($("#Status").find("option:selected").data("id"));
                }
            });
        }

        //加载状态备注
        function GetStatusReason(statusId) {
            if (!statusId || statusId < 0) {
                $("#StatusReasonDiv").hide();
                $("#StatusReasonId").html("");
                return;
            }
            $.ajax({
                url: "/Common/GetStatusReason?statusId=" + statusId,
                success: function (data) {
                    if (data && data.length > 0) {
                        var html = '<option value="">请选择</option>';
                        for (var i = 0; i < data.length; i++) {
                            html += "<option value='" + data[i].ID + "'>" + data[i].ReasonDescribe + "</option>";
                        }
                        $("#StatusReasonDiv").show();
                        $("#StatusReasonId").html(html);
                    } else {
                        $("#StatusReasonDiv").hide();
                        $("#StatusReasonId").html("");
                    }
                }
            });
        }

    </script>
}
